import UserToken from '@/models/mongo/UserToken'
import { MigrationInterface, QueryRunner } from 'typeorm'

export class userToken1728805804221 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    const userTokenRepository = queryRunner.manager.getMongoRepository(UserToken)
    userTokenRepository.createCollectionIndex('user_id', { name: 'user_id_index' })
    userTokenRepository.createCollectionIndex('token', { name: 'token_index', unique: true })
    userTokenRepository.createCollectionIndex('refresh_token_expired_at', { name: 'refresh_token_expired_at_index' })
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    const userTokenRepository = queryRunner.manager.getMongoRepository(UserToken)
    userTokenRepository.dropCollectionIndex('user_id_index')
    userTokenRepository.dropCollectionIndex('token_index')
    userTokenRepository.dropCollectionIndex('refresh_token_expired_at_index')
  }
}
